package com.alavente.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.alavente.objects.DemandeAchat;
import com.alavente.service.DemandeAchatManager;

public class DetailsDemandeAchatAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
				
		Integer numDemande = null;
		
		try {
			numDemande = Integer.parseInt(request.getParameter("numDemande"));
		}
		catch(NumberFormatException e) {}
		
		DemandeAchat demande = new DemandeAchatManager().getDemandeAchat(numDemande);
		
		if (demande == null) {
			request.setAttribute("error", "Cette annonce n'existe pas.");
			return mapping.findForward("failure");
		}
		
		request.setAttribute("demande", demande);		
		return mapping.findForward("success");
	}
}	
	
